package datamining.main;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.Collection;

import settings.Settings;
import utils.Database;

import datamining.algorithms.prefixspan.PrefixSpan;
import datamining.algorithms.prefixspan.PrefixSpanSequenceFactory;
import datamining.sequence.Sequence;
import datamining.sequence.SequenceFactory;
import datamining.strategy.RecursiveStrategy;
import datamining.visualisation.MainFrame;


/**
 * @author xujinghu, E-mail: jinghuxu@nudt.edu.cn
 * @date 2012-11-14  下午2:24:08
 * @version
 */
public class Experiment {

	MainFrame<Character> mainFrame;
	ArrayList<Sequence<Character>> parsedSequences = null;	//输入数据的内部表示
	Settings<Character> settings = null; // 环境参数设置

	public Experiment() {
		settings = new Settings<Character>("conf/config.properties");
		mainFrame = new MainFrame<Character>(settings);
		parsedSequences = new ArrayList<Sequence<Character>>();
	}

	/**
	 * @author xujinghu
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Experiment e = new Experiment();
		
		showTableModel();	//测试方法
	}

	public static void showTableModel() {	//测试数据库连接是否正常
		Database db = new Database("com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1:3306/snort", "root","rootadmin");
		String database = "ossim";
		String table = "plugin_sid";
		try {
			ResultSet rst = db.database_execute_single_command("select * from  "
					+ database + "." + table + ";");
			ResultSetMetaData meta = rst.getMetaData();
			int col = meta.getColumnCount();
			System.out.println("表" + table + "共有：" + col
					+ "个字段，这些字段是：");

			for (int i = 1; i <= col; i++) {
				System.out.println("字段名："
						+ meta.getColumnName(i)
						+ ", 类型："
						+ Database.typeToString(meta
								.getColumnType(i)));
			}

			System.out.println("--------------------------------------------------------------------------------------------------------------------------------------------------------");
			for (int j = 1; j < col + 1; j++) {
				System.out.print(meta.getColumnName(j) + "    |    ");
			}
			System.out.println("\n--------------------------------------------------------------------------------------------------------------------------------------------------------");
			ArrayList<String> row = new ArrayList<String>();
			
			if (rst.next()) {
				row.clear();
				row = Database.getRowValues(rst);
				for (int i = 0; i < row.size(); i++) {
					System.out.print(row.get(i) + "        ");
				}
				System.out.println();
			}
			// 关闭连接、释放资源
			rst.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
